class DocumentVersion < ActiveRecord::Base
  belongs_to :document
  has_attached_file :version,
                    :path => ":rails_root/documents/:class/:id/:style/:basename.:extension"

  class << self
    def current_version_id_for_document_id(doc_id)
      maximum(:version_number, :conditions => ["document_id = ?", doc_id])
    end

    def current_version_for_document_id(doc_id)
      find(:first, :conditions => ["document_id = ?", doc_id], :order => "version_number  desc")
    end
  end

  def kilobytes
   self.version_file_size / 1024
  end
end
